package org.rcy.ruicingmarket.interceptor;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author RuicyWu
 * @Date 2022/3/12 21:55
 */
public class RequestFromGateWayInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String gatewayauth = request.getHeader("Gateway-auth");
        String app = request.getHeader("app");
        if(StringUtils.isNotEmpty(gatewayauth)&&gatewayauth.equals("pass")){
            return true;
        }
        if(StringUtils.isNotEmpty(app)){
            return true;
        }
        response.setStatus(401);
        return false;
    }
}
